var arr=["网页","MP3","图片","视频","问答","新闻","地图","购物","站内"];

function changeBg(obj)
{//改变选项背景
	//alert(obj);
	
	var el=document.getElementById("span_"+obj);
	for(var i=1;i<=9;i++)
	{
		var all=document.getElementById("span_"+i);
		all.className="no_bg";
	}
	el.className="bg";
	
	var hidn='<INPUT name="tn" type="hidden">';
    hidn+='<INPUT name="ct" type="hidden">';
    hidn+='<INPUT name="lm" type="hidden">';
    hidn+='<INPUT name="cl" type="hidden">';
    hidn+='<INPUT name="rn" type="hidden">';
  
    hidn+='<INPUT name="hl" type="hidden" value="zh-CN">';
    hidn+='<INPUT name="biw" type="hidden" value="1263">';
    hidn+='<INPUT name="bih" type="hidden" value="577">';
    hidn+='<INPUT name="newwindow" type="hidden" value="1">';
    hidn+='<INPUT name="sa" type="hidden" value="N">';
    hidn+='<INPUT name="um" type="hidden" value="1">';
    hidn+='<INPUT name="safe" type="hidden" value="strict">';
    hidn+='<INPUT name="tbo" type="hidden">';
    hidn+='<INPUT name="tbs" type="hidden">';
    hidn+='<INPUT name="source" type="hidden">';
    hidn+='<INPUT name="tab" type="hidden">';
	
	var browser_type=getOs();
	
	if(obj==1)
	{
	  str='<form name="search_form" target="_blank" onSubmit="return gowhere();">';
	  str+=hidn;
		
	  str+='<a id="search_url" href="http://www.baidu.com" target="_blank" alt="点此打开网站" title="点此打开网站">';
	  str+='<img id="seek_logo" src="http://www.weekuu.com/ttday/static/image/ttday/baidu_logo.gif" />';
	  str+='</a>';
	  str+='<input id="search_box" type="text" name="word" value="" size="50" class="seek_txt"/>';
	  str+='<input type="submit" name="seek_btn" value="搜 索" class="seek_btn" />';
	  str+='<span id="seek_slt" class="seek_slt">';
	  str+='<input id="radio_1" type="radio" name="seek_slt" value="google" onClick="changeImg(1);" />谷歌';
	  str+='<input id="radio_2" type="radio" name="seek_slt" value="baidu" checked="true" onClick="changeImg(2);" />百度';
	  str+='</span>';
	  str+='<div style="clear:both;height:2px;"></div>';
	}
	else if(obj>=2&&obj<=7)
	{
	  str='<form name="search_form" id="search_form" target="_blank">';
	  str+=hidn;
	  
	  str+='<div class="bd_seek">';
	  str+='<a id="search_url" href="http://www.baidu.com" target="_blank" alt="点此打开网站" title="点此打开网站">';
	  str+='<img id="seek_logo" src="http://www.weekuu.com/ttday/static/image/ttday/bd_t'+ obj +'.gif" />';
	  str+='</a>';
	  str+='<input id="search_box" type="text" name="word" value="" size="50" class="seek_txt" />';
	  str+='<input type="button" name="bd_btn" value="搜 索" class="seek_btn" onclick="goSearch(1,'+ obj +');" />';
	  str+='<div style="clear:both;height:2px;"></div>';
	  str+='</div>';
	
	  str+='<div class="gg_seek">';
	  str+='<a id="search_url_g" href="http://www.google.com" target="_blank" alt="点此打开网站" title="点此打开网站">';
	  str+='<img id="seek_logo" src="http://www.weekuu.com/ttday/static/image/ttday/gg_t'+ obj +'.gif" />';
	  str+='</a>';
	  str+='<input id="search_box" type="text" name="q" value="" size="50" class="seek_txt" />';
	  str+='<input type="button" name="gg_btn" value="搜 索" class="seek_btn" onclick="goSearch(2,'+ obj +')" />';
	  str+='<div style="clear:both;height:2px;"></div>';
      str+='</div>';
	  
	  str+='</form>';
	}
	else if(obj==8)
	{
	 //淘宝图片及网址
	  str='<form name="search_form" target="_blank" onSubmit="return gowhere();">';
	  str+=hidn;
		
	  str+='<a id="search_url" href="http://www.taobao.com" target="_blank" alt="点此打开网站" title="点此打开网站">';
	  str+='<img id="seek_logo" src="http://www.weekuu.com/ttday/static/image/ttday/taobao_logo.gif" />';
	  str+='</a>';
	  str+='<input id="search_box" type="text" name="q" value="" size="50" class="seek_txt"/>';
	  str+='<input type="submit" name="seek_btn" value="搜 索" class="seek_btn" />';
	  str+='<span id="seek_slt" class="seek_slt">';
	  str+='<input id="radio_3" type="radio" name="seek_slt" value="taobao" checked="true" />淘宝';
	  str+='</span>';
	  str+='<div style="clear:both;height:2px;"></div>';
	}
	else if(obj==9)
	{
	 //站内搜索
	  str='<form name="search_form" target="_blank" onSubmit="return gowhere();">';
	  str+=hidn;
		
	  str+='<a id="search_url" href="http://www.ttday.com" target="_blank" alt="点此打开网站" title="点此打开网站">';
	  str+='<img id="seek_logo" src="http://www.weekuu.com/ttday/static/image/ttday/logo.jpg" />';
	  str+='</a>';
	  str+='<input id="search_box" type="text" name="kword" value="" size="50" class="seek_txt"/>';
	  str+='<input type="submit" name="seek_btn" value="搜 索" class="seek_btn" />';	
	  str+='<div style="clear:both;height:2px;"></div>';
	}
	
	document.getElementById("btm_seek").innerHTML=str;	
}

function goSearch(a,b)
{
 var tmp;
 if (a==1)
 {//MP3
	if(b==2)
	{//百度
	   $("search_box").setAttribute("name","word");
	   //alert(document.search_form.word.value);
	   //document.charset = "uft-8" 或 "gb2312";
	   document.charset="gb2312";
	   url = "http://mp3.baidu.com/m";
       document.search_form.tn.value = "baidump3";
       document.search_form.ct.value = "134217728";
       document.search_form.lm.value = "-1";
	   
	}
	else if(b==3)
	{//百度
	   $("search_box").setAttribute("name","word");
	   document.search_form.tn.value = "baiduiamge";
	   document.search_form.ct.value = "201326592";
	   document.search_form.cl.value = "2";
	   document.search_form.lm.value = "-1";
	   url = "http://image.baidu.com/i";
	   document.charset="gb2312";
	}
	else if(b==4)
	{//百度
	   $("search_box").setAttribute("name","word");
	   document.search_form.ct.value = "301989888";
	   document.search_form.rn.value = "20";
	   url = "http://video.baidu.com/v";
	   document.charset="gb2312";
	}	
	else if(b==5)
	{//百度
	   $("search_box").setAttribute("name","word");
	   url = "http://zhidao.baidu.com/q";
	   document.search_form.tn.value = "ikaslist";
	   document.search_form.ct.value = "17";
	   document.search_form.rn.value = "10";
	   document.charset="gb2312";
	}
	if(b==6)
	{//百度
	   $("search_box").setAttribute("name","word");
	   document.search_form.tn.value = "news";
	   document.search_form.cl.value = "2";
	   document.search_form.rn.value = "20";
	   url = "http://news.baidu.com/ns";
	   document.charset="gb2312";
	}
	else if(b==7)
	{//百度
	   $("search_box").setAttribute("name","s");
	   url = "http://map.baidu.com/";
	   document.charset="gb2312";
	}
	tmp=document.search_form.word.value;
 }
 else if(a==2)
 {//图片
	if(b==2)
	{//谷歌
	   $("search_box").setAttribute("name","q");
	   url = "http://www.google.cn/music/search";
	   document.charset="gb2312";
	}	
	else if(b==3)
	{//谷歌
	   $("search_box").setAttribute("name","q");
	   url = "http://www.google.com.hk/images";
	   document.search_form.tab.value = "wi"; 
	   document.charset="gb2312";
	}
	else if(b==4)
	{//谷歌
	   $("search_box").setAttribute("name","q");
	   url = "http://www.google.com.hk/search";
	   document.search_form.tab.value = "iv";
	   document.search_form.tbo.value = "u";
	   document.search_form.tbs.value = "vid:1";
	   document.search_form.source.value = "og";
	   document.charset="gb2312";
	}
	else if(b==5)
	{//谷歌
	   $("search_box").setAttribute("name","q");
	   document.search_form.tab.value = "w2";
	   url = "http://wenda.google.com.hk/wenda/search";
	   document.charset="gb2312";
	}
	else if(b==6)
	{//谷歌
	   $("search_box").setAttribute("name","q");
	   document.search_form.tab.value = "ln";
	   url = "http://news.google.com/news";
	   document.charset="gb2312";
	}
	else if(b==7)
	{//谷歌
	   $("search_box").setAttribute("name","q");
	   url = "http://ditu.google.cn/maps";
	   document.search_form.tab.value = "vl";
	   document.charset="gb2312";
	}
	tmp=document.search_form.q.value;
 }
 document.search_form.action = url;
 document.search_form.submit();
 return true;
}

function getOs() 
{ 
   var OsObject = ""; 
   if(navigator.userAgent.indexOf("MSIE")>0) { 
        return "MSIE"; 
   } 
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){ 
        return "Firefox"; 
   } 
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) { 
        return "Safari"; 
   } 
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){ 
        return "Camino"; 
   } 
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){ 
        return "Gecko"; 
   } 
} 

//得到样式表的对象
function getstyle(sname)
{ 
	for (var i=0;i<document.styleSheets.length;i++)
	{ 
		var rules; 
		if (document.styleSheets[i].cssRules)
		{ 
			rules = document.styleSheets[i].cssRules; 
		}
		else
		{ 
			rules = document.styleSheets[i].rules; 
		}
		
		for (var j=0;j<rules.length;j++)
		{ 
			if (rules[j].selectorText == sname)
			{ 
			 //selectorText 属性的作用是对一个选择的地址进行替换.意思应该是获取RULES[J]的CLASSNAME. 
			 return rules[j].style; 
			} 
		} 
	} 
} 


function changeSelect()
{//快捷通道
	var shortDiv=$("channel_item");
	if(shortDiv.style.display=="none")
	{
		shortDiv.style.display="block"
	}
	else
	{
		shortDiv.style.display="none"
	}
}

function trim(str)
{ //删除左右两端的空格    
	return str.replace(/(^\s*)|(\s*$)/g, "");    
}

function changeImg(a)
{
	if(a==1)
	{
		$("seek_logo").setAttribute("src","http://www.weekuu.com/ttday/static/image/ttday/google_logo.gif");
		search_url.href="http://www.google.com";
	}
	else
	{
		$("seek_logo").setAttribute("src","http://www.weekuu.com/ttday/static/image/ttday/baidu_logo.gif");
		search_url.href="http://www.baidu.com";
	}
}

function $(str)
{//获取对象
	return document.getElementById(str);
}

function gowhere()
{
 var url,item,check_who;
 
 //判断选中哪个搜索引擎
 for(var i=0;i<document.search_form.seek_slt.length;i++) 
 { 
	if(document.search_form.seek_slt[i].checked) 
	{ 
	 check_who=document.search_form.seek_slt[i].value;
	 break; 
	} 
 }
 
 //判断选中哪个搜索选项
 for(var j=1;j<=9;j++)
 {
	if($("span_"+j).className=="bg")
	{
		item=j;
		break;
	}
 } 

 if (item==1)
 {//网页
	if(check_who=="baidu")
	{//百度
	   $("search_box").setAttribute("name","word");
	   url = "http://www.baidu.com/s";
	   document.search_form.tn.value = "baidu"; 	
	}
	else
	{//谷歌
	   $("search_box").setAttribute("name","q");
	   url = "http://www.google.com.hk/search";
	}
 }
 else if (item==2)
 {//MP3
	if(check_who=="baidu")
	{//百度
	   $("search_box").setAttribute("name","word");
	   url = "http://mp3.baidu.com/m";
       document.search_form.tn.value = "baidump3";
       document.search_form.ct.value = "134217728";
       document.search_form.lm.value = "-1";	
	}
	else
	{//谷歌
	   $("search_box").setAttribute("name","q");
	   url = "http://www.google.cn/music/search";
	}
 }
 else if (item==3)
 {//图片
	if(check_who=="baidu")
	{//百度
	   $("search_box").setAttribute("name","word");
	   document.search_form.tn.value = "baiduiamge";
	   document.search_form.ct.value = "201326592";
	   document.search_form.cl.value = "2";
	   document.search_form.lm.value = "-1";
	   url = "http://image.baidu.com/i";	
	}
	else
	{//谷歌
	   $("search_box").setAttribute("name","q");
	   url = "http://www.google.com.hk/images";
	   document.search_form.tab.value = "wi"; 
	}
 }
 else if (item==4)
 {//视频
	if(check_who=="baidu")
	{//百度
	   $("search_box").setAttribute("name","word");
	   document.search_form.ct.value = "301989888";
	   document.search_form.rn.value = "20";
	   url = "http://video.baidu.com/v";	
	}
	else
	{//谷歌
	   $("search_box").setAttribute("name","q");
	   url = "http://www.google.com.hk/search";
	   document.search_form.tab.value = "iv";
	   document.search_form.tbo.value = "u";
	   document.search_form.tbs.value = "vid:1";
	   document.search_form.source.value = "og";
	}
 }
 else if (item==5)
 {//问答
	if(check_who=="baidu")
	{//百度
	   $("search_box").setAttribute("name","word");
	   url = "http://zhidao.baidu.com/q";
	   document.search_form.tn.value = "ikaslist";
	   document.search_form.ct.value = "17";
	   document.search_form.rn.value = "10";	
	}
	else
	{//谷歌
	   $("search_box").setAttribute("name","q");
	   document.search_form.tab.value = "w2";
	   url = "http://wenda.google.com.hk/wenda/search";
	}
 }
 else if (item==6)
 {//新闻
	if(check_who=="baidu")
	{//百度
	   $("search_box").setAttribute("name","word");
	   document.search_form.tn.value = "news";
	   document.search_form.cl.value = "2";
	   document.search_form.rn.value = "20";
	   url = "http://news.baidu.com/ns";	
	}
	else
	{//谷歌
	   $("search_box").setAttribute("name","q");
	   document.search_form.tab.value = "ln";
	   url = "http://news.google.com/news";
	}
 }
 else if (item==7)
 {//地图
	if(check_who=="baidu")
	{//百度
	   $("search_box").setAttribute("name","s");
	   url = "http://map.baidu.com/";	
	}
	else
	{//谷歌
	   $("search_box").setAttribute("name","q");
	   url = "http://ditu.google.cn/maps";
	   document.search_form.tab.value = "vl";
	}
 }
 else if (item==8)
 {//购物
	url = "http://s.taobao.com/search";
 }
 else (item==9)
 {//站内

 }

 document.search_form.action = url;
 return true;
}

function getFocus(n)
{
	if(n==1)
	{
		document.search_form.name.focus();
		$("search_box1").style.borderColor="#FFAA00";
		
		$("search_box2").style.borderColor="#7B9ABD";
	}
	else if(n==2)
	{
		document.search_form.q.focus();
		$("search_box1").style.borderColor="#FFAA00";
		
		$("search_box2").style.borderColor="#7B9ABD";		
	}
}

function check_login()
{
	if(document.login_form.username.value=="")	
	{
		alert("请输入用户名");
		document.login_form.username.focus();
		return false;
	}
	if(document.login_form.password.value=="")	
	{
		alert("请输入密码");
		document.login_form.password.focus();
		return false;
	}
	return true;
}

function Utf8ToGb2312(str1)
{
	var substr = "";
	var a = "";
	var b = "";
	var c = "";
	var i = -1;
	i = str1.indexOf("%");
		
	if(i==-1)
	{
	  return str1;
	}
    
	while(i!= -1)
	{
     if(i<3)
	 {
		substr = substr + str1.substr(0,i-1);
		str1 = str1.substr(i+1,str1.length-i);
		a = str1.substr(0,2);
		str1 = str1.substr(2,str1.length - 2);
		if(parseInt("0x" + a) & 0x80 == 0)
		{
		  	substr = substr + String.fromCharCode(parseInt("0x" + a));
		}
		else if(parseInt("0x" + a) & 0xE0 == 0xC0)
		{ //two byte
			b = str1.substr(1,2);
			str1 = str1.substr(3,str1.length - 3);
			var widechar = (parseInt("0x" + a) & 0x1F) << 6;
			widechar = widechar | (parseInt("0x" + b) & 0x3F);
			substr = substr + String.fromCharCode(widechar);
		}
		else
		{
			b = str1.substr(1,2);
			str1 = str1.substr(3,str1.length - 3);
			c = str1.substr(1,2);
			str1 = str1.substr(3,str1.length - 3);
			var widechar = (parseInt("0x" + a) & 0x0F) << 12;
			widechar = widechar | ((parseInt("0x" + b) & 0x3F) << 6);
			widechar = widechar | (parseInt("0x" + c) & 0x3F);
			substr = substr + String.fromCharCode(widechar);
		}
     }
     else 
	 {
      substr = substr + str1.substring(0,i);
      str1= str1.substring(i);
     }
     
	 i = str1.indexOf("%");
    }

    return substr+str1;
}
function AddFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}
function SetHome(obj,vrl)
{
    try
    {
            obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
    }
    catch(e){
            if(window.netscape) {
                    try {
                            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
                    } 
                    catch (e) { 
                            alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'"); 
                    }
                    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                    prefs.setCharPref('browser.startup.homepage',vrl);
             }
    }
}

